import Vue from 'vue'
import App from './App'


import {
	myRequest
} from 'apiutils/requestApi.js'
Vue.prototype.$myRequest = myRequest

//将毫秒转成时分秒		
Vue.prototype.formatSeconds =
	function(value) {
		var theTime = parseInt(value); // 秒
		var theTime1 = 0; // 分
		var theTime2 = 0; // 小时
		// alert(theTime);
		if (theTime > 60) {
			theTime1 = parseInt(theTime / 60);
			theTime = parseInt(theTime % 60);
			// alert(theTime1+"-"+theTime);
			if (theTime1 > 60) {
				theTime2 = parseInt(theTime1 / 60);
				theTime1 = parseInt(theTime1 % 60);
			}
		}
		var result = "" + parseInt(theTime) + "秒";
		if (theTime1 > 0) {
			result = "" + parseInt(theTime1) + "分" + result;
		}
		if (theTime2 > 0) {
			result = "" + parseInt(theTime2) + "小时" + result;
		}
		return result;
	};

//计算距离，参数分别为第一点的纬度，经度；第二点的纬度，经度
Vue.prototype.GetDistance =
	function(lat1, lng1, lat2, lng2) {
		var radLat1 = Rad(lat1);
		var radLat2 = Rad(lat2);
		var a = radLat1 - radLat2;
		var b = Rad(lng1) - Rad(lng2);
		var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
			Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
		s = s * 6378.137; // EARTH_RADIUS;
		s = Math.round(s * 10000) / 10000; //输出为公里
		var distance = s;
		var distance_str = "";
		if (parseInt(distance) >= 1) {
			s = distance_str = distance.toFixed(1) + "km";
		} else {
			s = distance_str = parseInt((distance * 1000)) + "m";
		}
		return s;
	};



//计算距离，参数分别为第一点的纬度，经度；第二点的纬度，经度
Vue.prototype.GetDistance =
	function(lat1, lng1, lat2, lng2) {
		var radLat1 = Rad(lat1);
		var radLat2 = Rad(lat2);
		var a = radLat1 - radLat2;
		var b = Rad(lng1) - Rad(lng2);
		var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
			Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
		s = s * 6378.137; // EARTH_RADIUS;
		s = Math.round(s * 10000) / 10000; //输出为公里
		var distance = s;
		var distance_str = "";
		if (parseInt(distance) >= 1) {
			s = distance_str = distance.toFixed(1) + "km";
		} else {
			s = distance_str = parseInt((distance * 1000)) + "m";
		}
		return s;
	};

//转百度经纬度
Vue.prototype.qqMapTransBMap =
	function(lng, lat) {
		let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
		let x = lng;
		let y = lat;
		let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
		let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
		let lngs = z * Math.cos(theta) + 0.0065;
		let lats = z * Math.sin(theta) + 0.006;

		return {
			lng: lngs.toFixed(7),
			lat: lats.toFixed(7)
		}
	};

//转qq经纬度
Vue.prototype.BMapTransqqMap =
	function(lng, lat) {
		let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
		let x = lng;
		let y = lat;
		let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
		let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
		let lngs = z * Math.cos(theta) - 0.0065;
		let lats = z * Math.sin(theta) - 0.006;

		return {
			lng: lngs.toFixed(7),
			lat: lats.toFixed(7)
		}
	};

//封装消息提示框
Vue.prototype.toast =
	function(title, icon = 'none', duration, options) {
		setTimeout(() => {
			wx.showToast({
				title: title || '',
				icon: icon,
			});
			setTimeout(() => {
				wx.hideToast();
			}, 2000)
		}, 300);

	};

//获取uuid 
Vue.prototype.uuid =
	function() {
		var s = [];
		var hexDigits = "0123456789abcdef";
		for (var i = 0; i < 36; i++) {
			s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
		}
		s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
		s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
		s[8] = s[13] = s[18] = s[23] = "-";

		var uuid = s.join("");
		return uuid;
	};

//反转
Vue.prototype.reverse =
	function(str) {
		return str.split('').reverse().join('')
	};
//生成时间戳
Vue.prototype.createTimestamp =
	function() {
		return parseInt(new Date().getTime()) + '';
	};

////进行经纬度转换为距离的计算
Vue.prototype.Rad =
	function(d) {
		return d * Math.PI / 180.0; //经纬度转换成三角函数中度分表形式。
	};


Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
